package design_pattern.proxy.dynamicProxy;

import design_pattern.proxy.staticProxy.AProductFactory;
import design_pattern.proxy.staticProxy.BProductFactory;
import design_pattern.proxy.staticProxy.ProductSaleProxy;

/**
 * @version 1.0.0
 * Created by cyd on 2024-07-27 14:15:15
 * @ClassName : design_pattern.proxy.dynamicProxy.Client
 * @Description : 客户类，调用不同的代理
 */
public class Client {


    void buyDirectly(Integer size) {
        BbSaleProxy target = new BbSaleProxy();
        target.saleWomanTools(size);
    }

    void buyFromDynamicProxyFromWomanToolsFactory(Integer size) {
        WomanToolsSaleProxy target = new BbSaleProxy();
        // 万能类，可以为任何目标代理，只需要将目标公司注入进去就行
        MyDynamicProxy myDynamicProxy = new MyDynamicProxy();
        myDynamicProxy.setObj(target);
        WomanToolsSaleProxy proxy = (WomanToolsSaleProxy) myDynamicProxy.getProxyInstance();
        // 可以代理任何接口
        proxy.saleWomanTools(size);
    }

    void buyFromDynamicProxyFromSaleProxyFromBFactory(String size) {
        ProductSaleProxy target = new BProductFactory();
        // 万能类，可以为任何目标代理，只需要将目标公司注入进去就行
        MyDynamicProxy myDynamicProxy = new MyDynamicProxy();
        myDynamicProxy.setObj(target);
        ProductSaleProxy proxy = (ProductSaleProxy) myDynamicProxy.getProxyInstance();
        proxy.saleSomething(size);
    }

    void buyFromDynamicProxyFromSaleProxyFromAFactory(String size) {
        ProductSaleProxy target = new AProductFactory();

        // 万能类，可以为任何目标代理，只需要将目标公司注入进去就行
        MyDynamicProxy myDynamicProxy = new MyDynamicProxy();
        myDynamicProxy.setObj(target);
        ProductSaleProxy proxy = (ProductSaleProxy) myDynamicProxy.getProxyInstance();
        proxy.saleSomething(size);
    }


}
